package com.niit.schoolhub.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.niit.schoolhub.system.mapper.YesapiOneArticlesMapper;
import com.niit.schoolhub.system.pojo.YesapiOneArticles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 轻量博客-文章 前端控制器
 * </p>
 *
 * @author kaguya
 * @since 2021-11-27
 */
@RestController
@CrossOrigin
@RequestMapping("/system/yesapiOneArticles")
public class YesapiOneArticlesController {
    @Autowired
    YesapiOneArticlesMapper yesapiOneArticlesMapper;
    @PostMapping("/set/createArticle")
    public YesapiOneArticles createArticle(@RequestBody YesapiOneArticles yesapiOneArticles){
        yesapiOneArticlesMapper.insert(yesapiOneArticles);
        return yesapiOneArticles;
    }

    @RequestMapping("/get/getAllArticle")
    public List<YesapiOneArticles> getAllArticle(){
        List<YesapiOneArticles> yesapiOneArticles = yesapiOneArticlesMapper.selectList(null);
        return yesapiOneArticles;
    }

    @GetMapping("/get/getArticleByid")
    public YesapiOneArticles getArticleByid(HttpServletRequest httpServletRequest){
        String articleid = httpServletRequest.getHeader("articleid");
        System.out.println(articleid);
        YesapiOneArticles yesapiOneArticles = yesapiOneArticlesMapper.selectById(articleid);
        System.out.println(yesapiOneArticles);
        return yesapiOneArticles;
    }

    @RequestMapping("/get/getLimitArticle/{current}")
    public List<YesapiOneArticles>getLimitArticle(@PathVariable(name = "current") Integer current){
        Page<YesapiOneArticles> Page = new Page<>(current,4);
        yesapiOneArticlesMapper.selectPage(Page,null);
        return Page.getRecords();
    }
    @RequestMapping("/test")
    public List<YesapiOneArticles>getLimitArticle(){
        Page<YesapiOneArticles> Page = new Page<>(1,5);
        yesapiOneArticlesMapper.selectPage(Page,null);
        return Page.getRecords();
    }
}

